#!/usr/bin/env bash

# Author:   Zhang Huangbin (michaelbibby <at> gmail.com)

#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------

# ----------------------------------------
# For Dovecot and dovecot-sieve. 
# ----------------------------------------

if [ X"${DISTRO}" == X"RHEL" ]; then
    export DOVECOT_VERSION='1.1'
    export DOVECOT_CONF='/etc/dovecot.conf'
    export DOVECOT_LDAP_CONF='/etc/dovecot-ldap.conf'
    export DOVECOT_MYSQL_CONF='/etc/dovecot-mysql.conf'
    export DOVECOT_DELIVER='/usr/libexec/dovecot/deliver'
elif [ X"${DISTRO}" == X"DEBIAN" -o X"${DISTRO}" == X"UBUNTU" ]; then
    export DOVECOT_VERSION='1.1'

    # Ubuntu 10.04 uses dovecot-1.2.x.
    [ X"${DISTRO_CODENAME}" == X"lucid" ] && export DOVECOT_VERSION='1.2'

    export DOVECOT_CONF='/etc/dovecot/dovecot.conf'
    export DOVECOT_LDAP_CONF='/etc/dovecot/dovecot-ldap.conf'
    export DOVECOT_MYSQL_CONF='/etc/dovecot/dovecot-mysql.conf'
    export DOVECOT_DELIVER='/usr/lib/dovecot/deliver'
elif [ X"${DISTRO}" == X"FREEBSD" ]; then
    export DOVECOT_VERSION='1.2'
    export DOVECOT_CONF='/usr/local/etc/dovecot.conf'
    export DOVECOT_LDAP_CONF='/usr/local/etc/dovecot-ldap.conf'
    export DOVECOT_MYSQL_CONF='/usr/local/etc/dovecot-mysql.conf'
    export DOVECOT_DELIVER='/usr/local/libexec/dovecot/deliver'
fi

# Name of LDA sieve plugin.
if [ X"${DOVECOT_VERSION}" == X"1.1" ]; then
    export DOVECOT_LDA_PLUGIN_SIEVE="cmusieve"
    export DOVECOT_LDA_PLUGIN_AUTOCREATE=''
elif [ X"${DOVECOT_VERSION}" == X"1.2" ]; then
    export DOVECOT_LDA_PLUGIN_SIEVE="sieve"
    export DOVECOT_LDA_PLUGIN_AUTOCREATE='autocreate'
fi

# Dovecot user & group.
export DOVECOT_USER='dovecot'
export DOVECOT_GROUP='dovecot'

# Log & logrotate files.
export DOVECOT_LOG_FILE='/var/log/dovecot.log'
export SIEVE_LOG_FILE='/var/log/sieve.log'
export DOVECOT_LOGROTATE_FILE="${LOGROTATE_DIR}/dovecot"
export SIEVE_LOGROTATE_FILE="${LOGROTATE_DIR}/sieve"

# Dovecot auth socket.
export DOVECOT_SOCKET_MUX='/var/spool/postfix/dovecot-auth'
export DOVECOT_SOCKET_MASTER='/var/run/dovecot/auth-master'

export DOVECOT_BIN='/usr/sbin/dovecot'
export DOVECOT_SIEVEC='/usr/libexec/dovecot/sievec'

# Do not starts with dot (.).
export SIEVE_RULE_FILENAME='dovecot.sieve'
export GLOBAL_SIEVE_FILE="${SIEVE_DIR}/${SIEVE_RULE_FILENAME}"

# Dovecot plugin: Expire.
# NOTE: dict process currently runs as root, so this file will be owned as root.
export DOVECOT_EXPIRE_DICT_BDB='/var/lib/dovecot/expire/expire.db'

# Dovecot quota warning.
export DOVECOT_QUOTA_WARNING_BIN='/usr/local/bin/dovecot-quota-warning.sh'
